package com.zysoft.common.entity;

import org.apache.commons.lang.builder.ToStringBuilder;

import com.zysoft.common.dao.ICommonDao;
import com.zysoft.common.util.ContextUtil;

public abstract class AbstractEntity implements java.io.Serializable {
    
    private static final long serialVersionUID = 2035013017939483936L;


    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

    
    public void save() {
    	ICommonDao commonDao = ContextUtil.getBean("ICommonDao");
    	commonDao.save(this);
    }
    
    public void delete() {
    	ICommonDao commonDao = ContextUtil.getBean("ICommonDao");
    	commonDao.deleteObject(this);
    }
    
    public void update() {
    	ICommonDao commonDao = ContextUtil.getBean("ICommonDao");
    	commonDao.update(this);
    }
    
    public void merge(){
    	ICommonDao commonDao = ContextUtil.getBean("ICommonDao");
    	commonDao.merge(this);
    }
    public void saveOrUpdate() {
    	ICommonDao commonDao = ContextUtil.getBean("ICommonDao");
    	commonDao.saveOrUpdate(this);
    }
    
    
/*    public <T extends AbstractEntity, PK extends Serializable>  T getById(PK id){
    	ICommonService commonService = SpringContextUtil.getBean("CommonService");
    	return (T) commonService.get(this.getClass(), id);
    }
    
    public List<? extends AbstractEntity> list(){
    	ICommonService commonService = SpringContextUtil.getBean("CommonService");
    	return commonService.listAll(this.getClass());
    }
*/    
     
}
